

use "Data/Census w-restrictions.dta", clear

drop if (year == 2010 & fyend <= 630) | (year == 2011 & fyend > 630)

gen log_capital = log(total_capital_outlays)
gen log_interest = log(total_interest_on_debt)
gen log_tax = log(total_taxes)
gen log_total_debt = log(total_debt_outstanding)


foreach var in log_capital log_interest log_tax {
gen l_`var' = l.`var'
gen l2_`var' = l2.`var'
gen f_`var' = f.`var'
gen f2_`var' = f2.`var'
gen f5_`var' = f5.`var'
}

tab year, gen(y)

rename ltd_iss_all_other ltd

xtreg f_log_interest y2-y18, fe
predict resid, residuals

drop if ltd > 30000 | ltd < 1000

gen bucket = .
 forvalues x = 1000(500)30000 {
 replace bucket = `x' if ltd > `x' - 500 & ltd <= `x' 
 }
 
gen bucket_2 = bucket * bucket
gen bucket_3 = bucket_2 * bucket

gen Qdummy = ltd <= 10000
gen bucket_Q = bucket * Qdummy
gen bucket2_Q = bucket_2 * Qdummy

collapse (mean) resid bucket_2-bucket_3 Qdummy bucket_Q bucket2_Q ltd, by(bucket)

drop if ltd < 5000 | ltd > 20000
replace resid = . if bucket >= 10000 & bucket <= 10500

reg resid bucket Qdummy bucket_Q 
predict q
reg resid bucket Qdummy bucket_Q if bucket > 10000
predict q2

replace bucket = bucket / 1000

twoway scatter resid bucket if bucket > 5 & bucket < 20, msymbol(smcircle) mfcolor(white) || lfit q bucket if bucket > 5 & bucket <= 10, lpattern(dash) || lfit q2 bucket if bucket >= 10 & bucket < 20, lpattern(dash) xtitle("Long Term Debt Issued, Year t") ytitle("Residuals from a Regression of Log Interest" "on Government and Year Fixed Effects, Year t+1", size(small)) legend(label (1 "Observed") label (2 "Counterfactual")) graphregion(color(white)) xline(10) legend(off)

graph save "Figure 7", replace